// Achievement by G3X / GeXeH - Enjoy
// Version 1.0

// Achievement: Get into the top 5 damage to humans list.

local total = achievements.GetValue( "Zombie Survival: Brain Eater", "total", 0 )
if ( achievements.IsGamemode( "Zombie Survival" ) || total == 5 ) then

	local function RcTopZombieDamages( msg )
		local indexx = msg:ReadShort()
		local brains = msg:ReadString()
		
		for i = string.len( brains ), 1, -1 do
			if ( string.sub( brains, i, i ) == " " ) then
				local brainsName = string.Left( brains, i - 2 )
					if ( LocalPlayer():Name() == brainsName && total != 5 ) then
						total = math.Clamp( total + 1, 0, 5 )
						achievements.Update( "Zombie Survival: Brain Eater", total / 5, total .. "/5" )
						achievements.SetValue( "Zombie Survival: Brain Eater", "total", total )
					end
			break
		end
		
end

		return indexx, brains
	end
	
	usermessage.AddHook( "RcTopZombieDamages", "Achievements.Zombie Survival:Brain Eater", RcTopZombieDamages )
	
	achievements.Register( "Zombie Survival: Brain Eater", "Get into the top 5 damage to humans list 5 times.", "achievements/zs_braineater", total / 5, total .. "/5" )
	
end